// pages/select/select.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		text: '',
		searchRecord:[],
		state:false,
		zt:0
	},
	state(e){
		this.setData({
			state:false,
			zt:e.currentTarget.dataset.id
		})
	},
	xl(e){
		this.setData({
			state:e.currentTarget.dataset.id
		})
	},
	onShow(){
		this.openHistorySearch()
		console.log(this.data.searchRecord)
	},
	openHistorySearch: function () {
	  this.setData({
	    searchRecord: wx.getStorageSync('searchRecord') || [],//若无储存则为空
	  })
	},
	ls(e){
		wx.navigateTo({
			url:'../list/list?xx='+e.currentTarget.dataset.id+'&state='+this.data.zt
		})
	},
	searchSubmitFn: function (e) {
	    var that = this
	    var inputVal = this.data.text
	    var searchRecord = this.data.searchRecord
	    if (inputVal == '') {
	      wx.showToast({
	      	title:"请输入搜索内容",
	      	icon:'none'
	      })
	    }
	    else {
			wx.navigateTo({
				url:'../list/list?xx='+this.data.text+'&state='+this.data.zt
			})
			console.log(this.data.text)
	      //将搜索值放入历史记录中,只能放前五条
	      if (searchRecord.length < 5) {
	        searchRecord.unshift(
	          {
	            value: inputVal,
	            id: searchRecord.length
	          }
	        )
	      }
	      else {
	        searchRecord.pop()//删掉旧的时间最早的第一条
	        searchRecord.unshift(
	          {
	            value: inputVal,
	            id: searchRecord.length
	          }
	        )
			
	      }
	    //将历史记录数组整体储存到缓存中
	    wx.setStorageSync('searchRecord', searchRecord)
	    }
	  },
	
	
	text(e) {
		this.setData({
			text: e.detail.value
		})
	}
})
